package com.ywk.wsServer;

import org.java_websocket.WebSocket;
import org.java_websocket.handshake.ClientHandshake;
import org.java_websocket.server.WebSocketServer;

import java.net.InetSocketAddress;

/**
 * 官网：https://github.com/TooTallNate/Java-WebSocket
 * @Author zbh
 * @Date 2023/5/4
 */
public class WsServer extends WebSocketServer {

    public WsServer(int port) {
        super(new InetSocketAddress(port));
    }

    public WsServer(InetSocketAddress address) {
        super(address);
    }

    @Override
    public void onOpen(WebSocket webSocket, ClientHandshake clientHandshake) {
        System.out.println();
    }

    @Override
    public void onClose(WebSocket webSocket, int i, String s, boolean b) {
        System.out.println("服务端已关闭");
    }

    @Override
    public void onMessage(WebSocket webSocket, String message) {
        System.out.println(  "服务端接收消息: " + message);
    }

    @Override
    public void onError(WebSocket webSocket, Exception e) {
        System.out.println("服务端报错信息：");
        e.printStackTrace();
    }

    @Override
    public void onStart() {
        System.out.println("服务端启动成功");
    }
}
